var app = new Vue({
    el: '#news',
    data() {
        return {
            msg: 'news',
            //产品总条数
            total: 100,
            //每页数据条数
            pageSize: '5',
            pageNo: 1,
            index: 3,
            bannerImage: '',
            newsTypeList: {},
            newsList: [],
            typeId: 0

        }
    },
    created() {
        this.getHeaderList();
        this.getNewsTypeList()
    },
    methods: {
        //获取新闻分类
        getNewsTypeList() {
            axios.get('news/service/newsCategory/findAll')
                .then(res => {
                    console.log(res)
                    this.newsTypeList = res.data.data;
                })
                .catch(err => {
                    console.error(err);
                })
        },
        //获取新闻列表
        getNewsList(id) {
            if (id === '') {
                id = this.typeId;
            }

            this.typeId = id;

            axios.get('news/service/newsCategory/findAll')
                .then(res => {
                    console.log(res)
                    this.newsTypeList = res.data.data;
                })
                .catch(err => {
                    console.error(err);
                })
        },
        //获取请求头
        getHeaderList() {
            var storage = window.sessionStorage;

            var c = storage.getItem("headerList");

            if (!c) {
                axios.get('system/service/viewMenu/findAll')
                    .then(res => {
                        this.headerList1 = res.data.data;
                        this.bannerImage = this.headerList1[this.index].bgImg
                        storage.setItem("headerList", JSON.stringify(this.headerList1));
                    })
                    .catch(err => {
                        console.error(err);
                    })
            } else {
                this.headerList1 = JSON.parse(c);
                this.bannerImage = this.headerList1[this.index].bgImg
            }
        }
    }
})